package org.example.bobofish.user.application.controller.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @author : yuxiong
 * @date : 2025/6/17
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseEntity<R> {
    private int code;
    private String message;
    private R data;
    private long timestamp;

    public ResponseEntity(int code, String message, R data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    public static <R> ResponseEntity<R> success(R data) {
        return new ResponseEntity<>(Code.SUCCESS.getCode(), Code.SUCCESS.getMessage(), data);
    }

    public static ResponseEntity<Void> success() {
        return new ResponseEntity<>(Code.SUCCESS.getCode(), Code.SUCCESS.getMessage(), null);
    }

    public static ResponseEntity<Void> error(int code, String message) {
        return new ResponseEntity<>(code, message, null);
    }

    @Getter
    @AllArgsConstructor
    enum Code {
        SUCCESS(200, "Success"),
        ;

        private int code;
        private String message;
    }
}
